import time
from datetime import datetime

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

#
# def test_01():
#创建浏览器驱动对象
driver=webdriver.Edge()
#你要测试的网址
driver.get("http://localhost/index.php")
#打开浏览器后先窗口最大化
driver.maximize_window()
driver.implicitly_wait(10)
#1.使用xpath定位定位tpshop首页登陆超链接，并执行点击
driver.find_element(By.CSS_SELECTOR,".red").click()
#2.使用id定位定位登陆页面用户名输入框输入用户名
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("13522963990")
#3.使用name定位定位登陆页面密码输入框,输入密码
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
#4.使用name定位定位登陆页面验证码输入框,输入验证码
driver.find_element(By.CSS_SELECTOR,"#verify_code").send_keys("8888")
#5.使用xpath定位登陆按钮执行点击,强制等待5s
driver.find_element(By.CSS_SELECTOR,"a[name='sbtbutton']").click()
# 2.在个人中心页面点击【账户设置】下【收货地址】
# driver.find_element(By.CSS_SELECTOR,"div[class='u-dt'] span").click()
ActionChains(driver).move_to_element(driver.find_element(By.CSS_SELECTOR,"div[class='u-dt'] span")).perform()

driver.find_element(By.CSS_SELECTOR,"div[class='u-dl'] a:nth-child(1)").click()

# （*）获取当前已经保存地址条数
oldAddress=driver.find_element(By.CSS_SELECTOR, "em:nth-child(2)").text
# 3.点击【增加新地址】:收货人信息= cus{当前时间}
driver.find_element(By.CSS_SELECTOR, "span[class='co_blue']").click()
# current_time =
str_time = time.strftime("%H%M%S")
driver.switch_to.frame("layui-layer-iframe100001")
# 4.完成新增地址操作
#在找下拉框元素时，可能会使用time.sleep(2)
time.sleep(1)
Select(driver.find_element(By.CSS_SELECTOR,"#province")).select_by_visible_text("河南省")
time.sleep(1)
Select(driver.find_element(By.CSS_SELECTOR,"#province")).select_by_visible_text("河南省")

Select(driver.find_element(By.CSS_SELECTOR,"#province")).select_by_visible_text("河南省")
# 5.控制滚动条移动到页面最底部
driver.execute_script("window.scollTo(0,1000)")

# 6.刷新下界面
driver.refresh()
# （*）再次获取当前已经保存地址条数
newAddress=driver.find_element(By.CSS_SELECTOR, "em:nth-child(2)").text

# （*）判断新增完后的地址条数是否+1 如果+1则打印新增成功,否则打印新增失败
if int(oldAddress)+1 == int(newAddress):
    pass
else:
    pass



time.sleep(5)
#浏览器驱动对象进行关闭
driver.quit()


